const Components = require("unplugin-vue-components/webpack");
const { ElementPlusResolver } = require("unplugin-vue-components/resolvers");
const path = require("path");
const title = "福袋星球渠道后台";
module.exports = {
  configureWebpack: {
    plugins: [
      Components({
        resolvers: [ElementPlusResolver()],
      }),
    ],
    // 为官方文档提供的npm install element-plus --save命令引入安装时会引入最新的版本（在安装时没有指定版本）。
    // 这个版本在使用webpack版本时大概率会出现这个问题。
    module: {
      rules: [
        {
          test: /\.mjs$/,
          include: /node_modules/,
          type: "javascript/auto",
        },
      ],
    },
  },
  chainWebpack: (config) => {
    config.plugin("html").tap((args) => {
      args[0].title = title;
      return args;
    });
  },
  //全局变量混入
  pluginOptions: {
    "style-resources-loader": {
      preProcessor: "less",
      patterns: [path.resolve(__dirname, "./src/assets/style/index.less")],
    },
  },
  devServer: {
    proxy: {
      "/api": {
        target: "https://dev.xiaocaoku.cn", // "http://magicbox.local.com",
        ws: true,
        changeOrigin: true,
        pathRewrite: {
          "^/api": "", // rewrite path
        },
      },
    },
  },
};
